<template>
  <div class="index-container">
    <div class="animated animatd-container bounceInUp">
      <div class="title">{{ indexInfo.slogan }}</div>
      <div class="desc">{{ indexInfo.desc }}</div>
      <div class="btn">进一步了解<span class="iconfont icon-rightArrow"></span></div>
    </div>
  </div>
  <div class="icon-container">
    <div class="advantage-wrap">
      <div class="advantage" v-for="item in indexInfo.advantage.list" :key="item.id">
        <div :class="['iconfont', item.icon]"></div>
        <div class="text">{{ item.text }}</div>
      </div>
    </div>
  </div>
  <div v-for="(item, idx) in indexInfo.project.list" :key="item.id"
       :class="['display-container', idx%2==0?'display-right':'display-left']">
    <div class="img-container">
      <img :src="item.displayImg" alt="项目展示">
    </div>
    <div class="text-container">
      <div class="display-title">{{ item.name }}</div>
      <div class="display-content">
        {{ item.desc }}
      </div>
      <div class="display-btn">
        了解更多
      </div>
    </div>
  </div>
  <div ref="advantage" class="advantage-container">
    <div class="title">
      {{indexInfo.trust.title}}
      <p class="desc">{{indexInfo.trust.desc}}</p>
    </div>
    <div class="advantage-wrap">
      <div class="advantage">
        <div class="number">{{ data.projectNum }}+</div>
        <div class="text">{{indexInfo.trust.list[0].text}}</div>
      </div>
      <div class="advantage">
        <div class="number">{{ data.governmentNum }}+</div>
        <div class="text">{{indexInfo.trust.list[1].text}}</div>
      </div>
      <div class="advantage">
        <div class="number">{{ data.produceNum }}+</div>
        <div class="text">{{indexInfo.trust.list[2].text}}</div>
      </div>
      <div class="advantage">
        <div class="number">{{ data.teamNum }}+</div>
        <div class="text">{{indexInfo.trust.list[3].text}}</div>
      </div>
    </div>
  </div>
  <div class="project-container">
    <div class="title">
      {{indexInfo.news.title}}
      <p class="desc">{{indexInfo.news.desc}}</p>
    </div>
    <div class="project-wrap">
      <div class="project" v-for="(item, idx) in indexInfo.news.list" :key="item.id">
        <img :src="item.displayImg" :alt="'news'+idx">
        <div class="text-container">
          <div class="date">
            <p class="day">08</p>
            <p class="year-month">2018.10</p>
          </div>
          <div class="desc">
            <p class="head">测绘地理增添科技含量</p>
            <p class="content">
              变革时代，测绘地理信息高新技术企业科技进步贡献率达到66.82%
            </p>
          </div>
          <div class="icon">
            <span class="iconfont icon-rightArrow"></span>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="honor-container">
    <div class="title">
      {{indexInfo.honor.title}}
      <p class="desc">{{indexInfo.honor.desc}}</p>
    </div>
    <div class="honor-wrap">
      <div class="honor" v-for="(item, idx) in indexInfo.honor.list" :key="item.title">
        <img :src="item.img" :alt="'honor'+idx">
        <div class="text-container">
          <div class="title">{{item.title}}</div>
          <div class="desc">{{item.desc}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref, onMounted, onUnmounted, reactive} from 'vue'

import {index} from "@/utils/data.js";
import DetailStructure from "@/components/common/DetailStructure.vue";

const advantage = ref();
let advantageWinHeight;

const indexInfo = index;

const numObj = {
  projectNum: indexInfo.trust.list[0].num,
  governmentNum: indexInfo.trust.list[1].num,
  produceNum: indexInfo.trust.list[2].num,
  teamNum: indexInfo.trust.list[3].num,
}
const data = reactive({
  advantageFlag: true,
  projectNum: 0,
  governmentNum: 0,
  produceNum: 0,
  teamNum: 0,
});
// 数据自增函数
const numAutoAdd = (time = 10) => {
  const _keys = Object.keys(numObj);
  let timeNum = time;
  _keys.forEach(item => {
    let k = 0;// 自增基数
    let strNum = data[item].toString();
    let timer = setInterval(() => {
      if (data[item] < numObj[item]) {
        timeNum -= 0.001;
        if (numObj[item].toString().length < 6) {
          k += 1;// 越加越快
          data[item] += k;
        } else {
          k += 500;
          data[item] += k;
        }
      } else {
        data[item] = numObj[item];
        clearInterval(timer);
      }
    }, timeNum);
  });
}
// 滚动触发函数
const pageScroll = (e) => {
  const scrollTop = Math.floor(document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset)
  // 优势
  if (scrollTop > advantageWinHeight + 100 && data.advantageFlag) {
    data.advantageFlag = false;
    numAutoAdd();
  }
}
onMounted(() => {
  advantageWinHeight = advantage.value.offsetTop;
  window.addEventListener('scroll', pageScroll);
})
onUnmounted(() => {
  window.removeEventListener('scroll', pageScroll);
})

</script>

<style lang="scss" scoped>
.index-container {
  width: 100%;
  height: 100vh;
  background: url("@/assets/imgs/index/bg2.jpg") no-repeat;
  background-size: 100% 100%  ;
  background-attachment: fixed;
  @include flex($row: center, $col: center, $direc: column);
  color: #ffffff;
  overflow: hidden;
  .animatd-container{
    @extend .animate-text-container;
    @include frostedGlass($blur:10px, $bg:rgba(121, 118, 118, 0.4));
    padding: 80px 120px;
    .title {
      font-size: 70px;
      font-weight: 2000;
      letter-spacing: 10px;
      margin-bottom: 20px;
    }

    .desc {
      font-size: 36px;
      margin-bottom: 20px;
    }

    .btn {
      font-size: 21px;
      cursor: pointer;
      line-height: 1.2;
      text-align: center;
      .icon-rightArrow {
        font-size: 18px;
        text-align: center;
        vertical-align: center;
      }
    }

    .btn:hover {
      text-decoration: underline;
    }
  }
}

.honor-container, .advantage-container, .project-container, .icon-container {
  padding: 50px 0;
  width: 100%;

  .title {
    font-size: 35px;
    font-weight: bold;
    text-align: center;
    padding-bottom: 30px;
    letter-spacing: 15px;

    .desc {
      font-size: 20px;
      font-weight: 400;
      letter-spacing: 5px;
    }
  }
}

.display-container {
  padding: 100px 200px;
  user-select: none;
  cursor: pointer;
  @include flex();

  .text-container {
    @include flex($direc: column, $row: center);

    .display-title {
      font-size: 30px;
      margin-bottom: 10px;
      border-bottom: 1px solid #000;
      font-weight: bold;
    }

    .display-content {
      text-align: left;
      text-indent: 2em;
      font-size: 25px;
    }

    .display-btn {
      font-size: 20px;
      text-decoration: underline;
      cursor: pointer;
      //line-height: 1.8;
      margin-top: 10px;
    }
  }
}

// 图片在左边
.display-left {
  background: linear-gradient(135deg, #e3e6e6, #ffffff);

  .text-container {
    text-align: left;
    margin-left: 100px;
  }
}

// 图片在右边
.display-right {
  background: linear-gradient(45deg, #ffffff, #e3e6e6);

  .text-container {
    text-align: right;
    margin-right: 100px;
  }
  .img-container {
    order: 1;
  }
}

.honor-container {
  //background: url("@/assets/imgs/index/advantageBg.jpg") no-repeat;
  .honor-wrap {
    padding: 0 10px;
    @include flex();

    .honor {
      flex: 1;
      height: 260px;
      margin: 20px;
      overflow: hidden;
      position: relative;
      border-radius: 5px;

      img {
        position: absolute;
        width: 100%;
        height: 100%;
        display: block;
        @include transition();
      }

      .text-container {
        position: absolute;
        box-sizing: border-box;
        cursor: pointer;
        width: 100%;
        height: 100%;
        padding: 0 20px;
        color: #ffffff;
        opacity: 0;
        @include flex($row: center, $col: center, $direc: column);
        @include transition();

        .title {
          //font-weight: bold;
          padding: 0;
          font-size: 20px;
          margin-bottom: 5px;
        }

        .desc {
          text-align: center;
        }
      }
    }

    .honor-disappear {
      img {
        filter: blur(5px) brightness(70%);
        transform: scale(0.8);
      }
    }

    .honor:hover {
      box-shadow: $boxShadow;

      img {
        transform: scale(1.1);
      }

      .text-container {
        opacity: 1;
        background: rgba(22, 22, 23, 0.5);
      }
    }
  }
}

.icon-container,.advantage-container {
  background: #fbfbfb;
  .title {
    font-size: 35px;
    padding-bottom: 20px;
  }

  .advantage-wrap {
    //width: 1800px;
    @include flex($wrap: wrap);
    margin: 0 auto;

    .advantage {
      //width: 50%;
      flex: 1;
      text-align: center;
      //font-weight: bold;
      padding: 10px 0;
      opacity: 1;
      @include transition();
      user-select: none;

      .iconfont {
        font-size: 60px;
        @include transition();
      }

      .number {
        font-size: 40px;
        font-weight: bold;
        color: $themeColor;
      }

      .text {
        font-size: 18px;
      }
    }

    .advantage:hover {
      .iconfont {
        //transform: scale(1.2);
      }
    }

    .advantage-disappear {
      opacity: 0;

      .iconfont {
        font-size: 16px;
      }
    }
  }
}

.project-container {
  background: linear-gradient(135deg, #ffffff, #dce1e1);
  @include flex($direc: column, $col: center);

  .project-wrap {
    width: $maxWidth + 300px;
    @include flex($wrap: wrap);

    .project {
      width: calc(33.333333% - 40px);
      height: 250px;
      margin: 40px 20px;
      border-radius: 5px;
      //overflow: hidden;
      position: relative;
      img{
        border-radius: 5px;
        width: 100%;
        height: 100%;
      }

      .text-container {
        position: absolute;
        bottom: 0;
        cursor: pointer;
        box-sizing: border-box;
        width: 90%;
        height: 100px;
        border-radius: 5px;
        padding: 15px;
        //color: #ffffff;
        overflow: hidden;
        box-shadow: $boxShadow;
        background: rgba(255, 255, 255, .8);
        @include flex($col: center);
        @include transition();
        @include frostedGlass($blur: 5px, $bg:rgba(255,255,255,.8));
        transform: translateY(35%) !important;

        .date {
          margin-right: 15px;

          .day {
            text-align: right;
            font-size: 25px;
            border-bottom: 1px solid #999;
            color: $themeColor;
          }

          .year-month {
          }
        }

        .desc {
          flex: 1;
          margin-right: 10px;

          .head {
            font-size: 18px;
            margin-bottom: 3px;
            @include textEllipsis($line: 1);
            //color: $themeColor;
            font-weight: bold;
          }

          .content {
            font-size: 15px;
            @include textEllipsis($line: 2);
          }
        }

        .icon {
          width: 0;
          opacity: 0;
          text-align: right;
          @include transition();
          color: $themeColor;
        }
      }
    }

    .project:hover {
      box-shadow: $boxShadow;

      .text-container {
        width: 100%;
        //padding-left: 30px;
        .icon {
          width: 20px;
          opacity: 1;
        }
      }
    }
  }
}

</style>
